<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
%>

<!--  添加部门 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
		<title>添加部门</title>
	<link href="<%=path %>/css/index_css.css" rel="stylesheet" type="text/css" />
	<script language="javascript" src="<%=path %>/js/syAjax.js"></script>
	<script type="text/javascript">
		var objectHIDDENID;
		var orgId;
	      function checkID()
	      {
	         var organizationId=document.getElementById("organizationId");
	        syAjax.request("post","<%=path %>/checkIDorganizationAction.action","organization.organizationId="+organizationId.value,{success:initSuccessResult1,fail:onFail,type:'plain'});
	      }
	      
	      function initSuccessResult1(response)
	      {
	        if(response=="true")
	       {
	         var name=document.getElementById("orgName");
	         var sort=document.getElementById("sort");
	         var organizationId=document.getElementById("organizationId");
	         //2010-10-12  添加设置部门负责人
	         var paramArr="";
	         
	         var userId =document.getElementsByName("UserId");
			 if(userId!=null && userId.length>0){
				for(var i=0;i<userId.length;i++){
					paramArr+=userId[i].value+",";
				}
			 }
	         
	         syAjax.request("post","<%=path %>/saveOrganizationorganizationAction.action","organization.organizationId="+organizationId.value+"&organization.name="+name.value+"&organization.sort="+sort.value+"&organization.orgType="+document.getElementById("type").value+"&UserIds="+paramArr+"&years=${applicationScope.currentYear }&role.roleId=bmfzr",{success:initSuccessResult,fail:onFail,type:'plain'});
	       }else
	       {
	         alert("编号已存在！");
	       }
	      }
	      
      //提交
      function onSub()
      {
        var name=document.getElementById("orgName");
        var sort=document.getElementById("sort");
        var organizationId=document.getElementById("organizationId");
        if(organizationId.value=="")
        {
          alert("编号不能为空！");
          organizationId.focus();
          return;
        }
        if(name.value=="")
        {
          alert("名称不能为空！");
          name.focus();
          return;
        }
        if(!/^-?[\d]{0,9}$/.test(sort.value))
        {
          alert("显示序号应为数字！");
          sort.value="";
          sort.focus();
          return;
        }
        	if(/.*[\u4e00-\u9fa5]+.*$/.test(organizationId.value)) 
			{ 
				alert("编号不能含有汉字！"); 
				return false; 
			} 
        checkID();
      }
      
      function initSuccessResult(data){
		 parent.refreshJsp();
	  }
	  function giveParamArr(){
	  		return document.getElementById(objectHIDDENID).value;
	  }
	function doChooseUser(returnStr){
	//原版内容
		var idStr;
		if(returnStr==undefined){
			return;
		}
		if(returnStr!=null && returnStr!=""){
			var UserArr = returnStr.substring(0,returnStr.length-1).split(",");
			var UserNameStr="";
				for(var i=0;i<UserArr.length;i++){
					var user=UserArr[i];
					var sonArr=user.split("_");
					if((i+1)%5==0){
						UserNameStr+="&nbsp;&nbsp;"+sonArr[1]+"&nbsp;&nbsp;&nbsp;"+"<input name=\"UserId\" type=\"hidden\" value=\""+sonArr[0]+"\"/><br>";
					}else{
						UserNameStr+="&nbsp;&nbsp;"+sonArr[1]+"&nbsp;&nbsp;&nbsp;"+"<input name=\"UserId\" type=\"hidden\" value=\""+sonArr[0]+"\"/>";
					}
					idStr+=sonArr[0]+",";
				}
				document.getElementById("UserIds").value=idStr;
				if(UserNameStr!=""){									
					document.getElementById("pName").innerHTML=UserNameStr;					
				}	
		}else{
			document.getElementById("pName").innerHTML="点击此处设置部门负责人";
		}
	}
	  function choseUser(){
	  objectHIDDENID="UserIds";
	  parent.objectHIDDENID=objectHIDDENID;
	  if('${applicationScope.currentYear}'==null || '${applicationScope.currentYear}'==""){
		alert("未设置当前年度，请通知管理员进行设置！");
		return;
	   }
       var url="<%=path%>/toSelectTeacherorganizationAction.action?years=${applicationScope.currentYear}&role.roleId=bmfzr&actionURL=&t="+new Date();	

	   parent.displayModuleDiv(url);
	   
	   
	   
    }
	</script>
  </head>
  
  <body bgcolor="#ECE9D8">
   <form action="<%=path %>/saveOrganizationorganizationAction.action" method="post">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="41%" bgcolor="#ECE9D8">&nbsp;</td>
    <td width="59%" align="left" bgcolor="#ECE9D8">&nbsp;</td>
  </tr>
  <tr>
    <td height="30" align="right" bgcolor="#ECE9D8" class="f_6">编号：</td>
    <td align="left" bgcolor="#ECE9D8" class="f_6"><input type="text" name="organization.organizationId" id="organizationId" size="7" maxlength="20"/></td>
  </tr>
  <tr>
    <td height="30" align="right" bgcolor="#ECE9D8" class="f_6">部门名称：</td>
    <td align="left" bgcolor="#ECE9D8" class="f_6"><input type="text" name="organization.name" id="orgName" maxlength="25"/></td>
  </tr>
  <tr>
     <td height="30" align="right" bgcolor="#ECE9D8" class="f_6">部门负责人：</td>
     <td align="left">
     <div style="border:1px;border-style:dotted; background-color: #FFFFFF;width: 150px" onclick="choseUser();" class="border_3"onmouseover="this.style.backgroundColor='#e4f5ff'" onmouseout="this.style.backgroundColor=''" style="cursor:pointer;" id="pName">
          点击此处设置部门负责人
     </div>
     <input type="hidden"  value="" id="UserIds" />
     </td>
  </tr>
  <tr>
    <td height="30" align="right" bgcolor="#ECE9D8"><span class="f_6">显示序号：</span></td>
    <td align="left" bgcolor="#ECE9D8" class="f_6">
    	<input type="text" name="organization.sort" id="sort" value="0" />
    	<input type="hidden" name="organization.orgType" value="2" id="type" />
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center" bgcolor="#ECE9D8">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="center" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td bgcolor="#ECE9D8">&nbsp;</td>
    <td height="40" align="left" bgcolor="#ECE9D8"><label>
      <input type="button" onclick="onSub();" name="Submit" value="提 交" />
    </label></td>
  </tr>
</table>
</form>
  </body>
</html>
